home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Tools / CreatorAndBundle.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  4.8 KB  |  181 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // CreatorAndBundle.cp 
  3. // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
  4. // CreatorAndBundle -- post process application for bundle resource and shared bit
  5. //----------------------------------------------------------------------------------------
  6.  
  7. // MacApp
  8.  
  9. #ifndef __UCPLUSTOOL__
  10. #include <UCPlusTool.h>
  11. #endif
  12.  
  13. // ToolBox
  14.  
  15. #ifndef __FINDER__
  16. #include <Finder.h>
  17. #endif
  18.  
  19. #ifndef __MEMORY__
  20. #include <Memory.h>
  21. #endif
  22.  
  23. #ifndef __RESOURCES__
  24. #include <Resources.h>
  25. #endif
  26.  
  27.  
  28. class TCreatorAndBundleTool : public TCPlusTool
  29. {
  30.     MA_DECLARE_CLASS;
  31.  
  32.   public:
  33.     TCreatorAndBundleTool();    // constructor
  34.     
  35.     virtual ~TCreatorAndBundleTool();
  36.         // Destructor
  37.     
  38.     void ICreatorAndBundleTool(int argc, char** argv);
  39.     
  40.     virtual void DoProcessFileArg(const CStr255& arg);    // override
  41.     
  42.     virtual void DoToolAction(); // override
  43.     
  44.     void DoAutoMagicCreatorAndBundleAndSharedBit();
  45.  
  46.   protected:
  47.     CStr255 fResFileName;
  48.  
  49. };
  50.  
  51.  
  52. TCreatorAndBundleTool* gCreatorAndBundleTool;        // The tool
  53.  
  54.  
  55. //========================================================================================
  56. // CLASS TCreatorAndBundleTool
  57. //========================================================================================
  58. #undef Inherited
  59. #define Inherited TCPlusTool
  60.  
  61. #pragma segment TRes
  62. MA_DEFINE_CLASS_M1(TCreatorAndBundleTool, Inherited);
  63.  
  64. //----------------------------------------------------------------------------------------
  65. // TCreatorAndBundleTool constructor
  66. //----------------------------------------------------------------------------------------
  67. #pragma segment TRes
  68.  
  69. TCreatorAndBundleTool::TCreatorAndBundleTool()
  70. {
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // TCreatorAndBundleTool destructor
  75. //----------------------------------------------------------------------------------------
  76. #pragma segment MADestructorRes
  77.  
  78. TCreatorAndBundleTool::~TCreatorAndBundleTool()
  79. {
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. // TCreatorAndBundleTool::ICreatorAndBundleTool: 
  84. //----------------------------------------------------------------------------------------
  85. #pragma segment TInit
  86.  
  87. void TCreatorAndBundleTool::ICreatorAndBundleTool(int argc, char** argv)
  88. {
  89.     this->ICPlusTool(argc, argv);
  90. }
  91.  
  92. //----------------------------------------------------------------------------------------
  93. // TCreatorAndBundleTool::DoProcessFileArg: 
  94. //----------------------------------------------------------------------------------------
  95. #pragma segment TInit
  96.  
  97. void TCreatorAndBundleTool::DoProcessFileArg(const CStr255& arg)
  98. {
  99.     if (fResFileName.Length() > 0)
  100.         this->Stop("Sorry… only smart enough to process one file");
  101.     else
  102.         fResFileName = arg;
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. // TCreatorAndBundleTool::DoAutoMagicCreatorAndBundleAndSharedBit: 
  107. //----------------------------------------------------------------------------------------
  108. #pragma segment TRes
  109.  
  110. typedef OSType** OSTypeHandle;
  111.  
  112. void TCreatorAndBundleTool::DoAutoMagicCreatorAndBundleAndSharedBit()
  113. {
  114.     CStr255 aName;
  115.     FInfo theFInfo;
  116.     OSTypeHandle theBundle;
  117.     
  118.     aName = fResFileName;
  119.     FailOSErr(GetFInfo(aName, 0, &theFInfo));
  120.     theBundle = (OSTypeHandle)Get1IndResource('BNDL', 1);
  121.     if (theBundle != NULL)
  122.     {
  123.         theFInfo.fdCreator = **theBundle;
  124.         theFInfo.fdFlags |= kHasBundle;
  125.     }
  126.     else
  127.     {
  128.         theFInfo.fdCreator = '????';
  129.         theFInfo.fdFlags &= (~kHasBundle);
  130.     }
  131.     theFInfo.fdFlags |= kIsShared;    // by default MacApp apps can be shared cause they don't write back to themselves.
  132.  
  133.     FailOSErr(SetFInfo(aName, 0, &theFInfo));
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // TCreatorAndBundleTool::DoToolAction: 
  138. //----------------------------------------------------------------------------------------
  139. #pragma segment TRes
  140.  
  141. void TCreatorAndBundleTool::DoToolAction()
  142. {
  143.     CStr255 aName;
  144.     short ref;
  145.     
  146.     if (fResFileName.IsEmpty())
  147.         this->Stop("No filename specified");
  148.  
  149.     aName = fResFileName;
  150.  
  151.     SetResLoad(FALSE);            // avoid preloads
  152.     ref = OpenResFile(aName);
  153.     SetResLoad(TRUE);
  154.     if (ref == -1)
  155.         FailResError();
  156.  
  157.     this->DoAutoMagicCreatorAndBundleAndSharedBit();
  158.  
  159.     CloseResFile(ref);
  160.     FailResError();
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. // main: 
  165. //----------------------------------------------------------------------------------------
  166. #pragma segment TRes
  167.  
  168. void main(int argc, char** argv)
  169. {
  170.     InitUCPlusTool();
  171.     
  172.     gCreatorAndBundleTool = new TCreatorAndBundleTool;
  173.     gCreatorAndBundleTool->ICreatorAndBundleTool(argc,argv);
  174.     gCreatorAndBundleTool->Run();
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. // End of CreatorAndBundle.cp
  179.  
  180. #pragma segment Inline
  181.